package com.justnow.offer;

import java.util.Scanner;


/**
 * @author justnow
 * Created on 2020-09-17
 * Description
 * //        2
 * //        2 2
 * //        .E
 * //        S.
 * //        YES
 * //        2 2
 * //        #E
 * //        S#
 * //        NO
 */
public class Solution54 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int cols = scanner.nextInt();
            int rows = scanner.nextInt();
            scanner.nextLine();
            char[][] chars = new char[cols][rows];
            int sk = 0, sl = 0, ek = 0, el = 0;
            for (int j = 0; j < cols; j++) {
                String str = scanner.nextLine();
                
                char[] chars1 = str.toCharArray();
                for (int m = 0; m < chars1.length; m++) {
                    if ('E' == chars1[m]) {
                        ek = j;
                        el = m;
                    }
                }
                chars[j] = chars1;
            }
            int flag = 0;
            for (int k = 0; k < chars.length; k++) {
                for (int l = 0; l < chars[0].length; l++) {
                    if (chars[k][l] == 'S') {
                        if (dfs(k, l, chars, ek, el)) {
                            System.out.println("YES");
                            flag = 1;
                            break;
                        }
                    }
                }
                if (flag == 1) {
                    break;
                }
            }
            if (flag == 0) {
                System.out.println("NO");
            }
        }

    }

    private static boolean dfs(int k, int l, char[][] chars, int ek, int el) {
        if (k < 0 || k >= chars.length || l < 0 || l >= chars[0].length || chars[k][l] == '#') {
            return false;
        }

        if (chars[k][l] == 'E') return true;

        char temp = chars[k][l];
        chars[k][l] = '#';
        boolean res = dfs(k - 1, l, chars, ek, el) || dfs(k + 1, l, chars, ek, el)
                || dfs(k, l - 1, chars, ek, el) || dfs(k, l + 1, chars, ek, el);
        chars[k][l] = temp;
        return res;
    }
}
